﻿using System;
using System.Collections;
using UnityEngine;
using DG.Tweening;

public class Machine : MonoBehaviour
{
    public SolutionObject solutionObjectPrefab;
    public float handleTime = 3f; // 处理时间

    public bool InUse { get; private set; }

    public void BuySolutionObject(Action<SolutionObject> onSolutionObjectOut)
    {
        StartCoroutine(HandleSolutionObject(onSolutionObjectOut));
    }

    private IEnumerator HandleSolutionObject(Action<SolutionObject> onSolutionObjectOut)
    {
        InUse = true;
        transform.DOShakeScale(handleTime, 0.3f);
        yield return new WaitForSeconds(handleTime);

        AudioManager.Instance.PlaySound("GotSolution");
        var coffee = Instantiate(solutionObjectPrefab, transform.position, Quaternion.identity);
        onSolutionObjectOut?.Invoke(coffee);

        InUse = false;
    }
}